package com.cqu.lpss.service.impl;

import com.cqu.lpss.mapper.TextInfoMapper;
import com.cqu.lpss.pojo.Image;
import com.cqu.lpss.pojo.PageBean;
import com.cqu.lpss.pojo.Textinfo;
import com.cqu.lpss.service.TextInfoInterface;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
@Slf4j
public class TextInfoImpl implements TextInfoInterface {
    @Autowired
    TextInfoMapper textInfoMapper;
    @Override
    public PageBean<Textinfo> list(int page, int pageSize, String textTitle, String textUrl) {
        PageHelper.startPage(page,pageSize);
        List<Textinfo> textlist = textInfoMapper.list(textTitle, textUrl);
        Page<Textinfo> pagelist = (Page<Textinfo>) textlist;
        PageBean<Textinfo> pageBean = new PageBean<>(pagelist.getTotal(),pagelist);
        return pageBean;
    }

    @Override
    public int insert(Textinfo textinfo) {
        textinfo.setTextCreatetime(new Timestamp(System.currentTimeMillis()));
        int ans = textInfoMapper.insert(textinfo.getTextTitle(),textinfo.getTextUrl(),textinfo.getTextCreatetime());
        return ans;
    }

    @Override
    public List<Textinfo> listall() {
        return textInfoMapper.listall();
    }
}
